using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{

    public partial class VVKADR
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                case "TST":
                default:
                    #region=========
                    dwReturn["VKAMANDANT"] = app.Mandant;
                    dwReturn["VKASA"] = "  ";
                    dwReturn["VKAAUFKRS"] = "  ";
                    dwReturn["VKAAUFLFD"] = "000000";
                    dwReturn["VKAAUFPOS"] = "000";
                    dwReturn["VKAAENDST"] = "000";
                    dwReturn["VKALNAME1"] = "                                        ";
                    dwReturn["VKALNAME2"] = "                                        ";
                    dwReturn["VKALSTRASSE1"] = "                                        ";
                    dwReturn["VKALSTRASSE2"] = "                                        ";
                    dwReturn["VKALLKZ"] = "CN ";
                    dwReturn["VKALPLZ"] = "            ";
                    dwReturn["VKALORT"] = "HK                                      ";
                    dwReturn["VKALBZ"] = "  ";
                    dwReturn["VKALBZBEZ"] = "             ";
                    dwReturn["VKALCOUNTY"] = "    ";
                    dwReturn["VKALCITY"] = "    ";
                    dwReturn["VKABNAME1"] = "                                        ";
                    dwReturn["VKABNAME2"] = "                                        ";
                    dwReturn["VKABSTRASSE1"] = "                                        ";
                    dwReturn["VKABSTRASSE2"] = "                                        ";
                    dwReturn["VKABLKZ"] = "   ";
                    dwReturn["VKABPLZPF"] = "            ";
                    dwReturn["VKABPOSTF"] = "               ";
                    dwReturn["VKABPLZ"] = "            ";
                    dwReturn["VKABORT"] = "                                        ";
                    dwReturn["VKABBZ"] = "  ";
                    dwReturn["VKABBZBEZ"] = "             ";
                    dwReturn["VKABCOUNTY"] = "    ";
                    dwReturn["VKABCITY"] = "    ";
                    dwReturn["VKABANSPNA"] = "                                        ";
                    dwReturn["VKAADRSL1"] = "        ";
                    dwReturn["VKAKUNDNR1"] = "        ";
                    dwReturn["VKAANZ1"] = "01";
                    dwReturn["VKAADRSLK11"] = "        ";
                    dwReturn["VKAKUNDNRK11"] = "        ";
                    dwReturn["VKAANZK11"] = "00";
                    dwReturn["VKAADRSLK21"] = "        ";
                    dwReturn["VKAKUNDNRK21"] = "        ";
                    dwReturn["VKAANZK21"] = "00";
                    dwReturn["VKAADRSL2"] = "        ";
                    dwReturn["VKAKUNDNR2"] = "00000000";
                    dwReturn["VKAANZ2"] = "01";
                    dwReturn["VKAADRSLK12"] = "        ";
                    dwReturn["VKAKUNDNRK12"] = "        ";
                    dwReturn["VKAANZK12"] = "00";
                    dwReturn["VKAADRSLK22"] = "        ";
                    dwReturn["VKAKUNDNRK22"] = "        ";
                    dwReturn["VKAANZK22"] = "00";
                    dwReturn["VKAADRSL3"] = "        ";
                    dwReturn["VKAKUNDNR3"] = "        ";
                    dwReturn["VKAANZ3"] = "00";
                    dwReturn["VKAADRSLK13"] = "        ";
                    dwReturn["VKAKUNDNRK13"] = "        ";
                    dwReturn["VKAANZK13"] = "00";
                    dwReturn["VKAADRSLK23"] = "        ";
                    dwReturn["VKAKUNDNRK23"] = "        ";
                    dwReturn["VKAANZK23"] = "00";
                    dwReturn["VKAFREITXT"] = "J";
                    dwReturn["VKAAESTAT"] = "A";
                    dwReturn["VKABESTTXT"] = "N";
                    dwReturn["VKAFILLER4"] = "                                                                                                  ";
                    dwReturn["VKAAENZL"] = "6";
                    dwReturn["VKAAENB"] = "        ";
                    dwReturn["VKAAEND"] = "0";
                    dwReturn["VKANEUB"] = "        ";
                    dwReturn["VKANEUD"] = "0";

                    #endregion
                    break;
            }
        }
        public void InsertVKADR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
           
            dwData["VKANEUB"] = app.User; ;
            dwData["VKANEUD"] = date;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {

                case "YGR":
                case "YCC":
                case "TST":
                default:
                    or1.CommandText = "INSERT INTO VKADR ( VKAMANDANT,VKASA,VKAAUFKRS,VKAAUFLFD,VKAAUFPOS,VKAAENDST,VKALNAME1,VKALNAME2,VKALSTRASSE1,VKALSTRASSE2,VKALLKZ,VKALPLZ,VKALORT,VKALBZ,VKALBZBEZ,VKALCOUNTY,VKALCITY,VKABNAME1,VKABNAME2,VKABSTRASSE1,VKABSTRASSE2,VKABLKZ,VKABPLZPF,VKABPOSTF,VKABPLZ,VKABORT,VKABBZ,VKABBZBEZ,VKABCOUNTY,VKABCITY,VKABANSPNA,VKAADRSL1,VKAKUNDNR1,VKAANZ1,VKAADRSLK11,VKAKUNDNRK11,VKAANZK11,VKAADRSLK21,VKAKUNDNRK21,VKAANZK21,VKAADRSL2,VKAKUNDNR2,VKAANZ2,VKAADRSLK12,VKAKUNDNRK12,VKAANZK12,VKAADRSLK22,VKAKUNDNRK22,VKAANZK22,VKAADRSL3,VKAKUNDNR3,VKAANZ3,VKAADRSLK13,VKAKUNDNRK13,VKAANZK13,VKAADRSLK23,VKAKUNDNRK23,VKAANZK23,VKAFREITXT,VKAAESTAT,VKABESTTXT,VKAFILLER4,VKAAENZL,VKAAENB,VKAAEND,VKANEUB,VKANEUD)"
                    + " VALUES (:VKAMANDANT:,:VKASA:,:VKAAUFKRS:,:VKAAUFLFD:,:VKAAUFPOS:,:VKAAENDST:,:VKALNAME1:,:VKALNAME2:,:VKALSTRASSE1:,:VKALSTRASSE2:,:VKALLKZ:,:VKALPLZ:,:VKALORT:,:VKALBZ:,:VKALBZBEZ:,:VKALCOUNTY:,:VKALCITY:,:VKABNAME1:,:VKABNAME2:,:VKABSTRASSE1:,:VKABSTRASSE2:,:VKABLKZ:,:VKABPLZPF:,:VKABPOSTF:,:VKABPLZ:,:VKABORT:,:VKABBZ:,:VKABBZBEZ:,:VKABCOUNTY:,:VKABCITY:,:VKABANSPNA:,:VKAADRSL1:,:VKAKUNDNR1:,:VKAANZ1:,:VKAADRSLK11:,:VKAKUNDNRK11:,:VKAANZK11:,:VKAADRSLK21:,:VKAKUNDNRK21:,:VKAANZK21:,:VKAADRSL2:,:VKAKUNDNR2:,:VKAANZ2:,:VKAADRSLK12:,:VKAKUNDNRK12:,:VKAANZK12:,:VKAADRSLK22:,:VKAKUNDNRK22:,:VKAANZK22:,:VKAADRSL3:,:VKAKUNDNR3:,:VKAANZ3:,:VKAADRSLK13:,:VKAKUNDNRK13:,:VKAANZK13:,:VKAADRSLK23:,:VKAKUNDNRK23:,:VKAANZK23:,:VKAFREITXT:,:VKAAESTAT:,:VKABESTTXT:,:VKAFILLER4:,:VKAAENZL:,:VKAAENB:,:VKAAEND:,:VKANEUB:,:VKANEUD:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }

            Connect2Proxy(or1);
        }
        public DataSet QueryVKADR(DataRow dwData, int option = 1)
        {
            DataSet Result;

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VKADR WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM VKADR   "
                                     + "WHERE  VKAMANDANT=:VKAMANDANT: AND VKASA=:VKASA: AND VKAAUFKRS=:VKAAUFKRS: AND VKAAUFLFD=:VKAAUFLFD: AND VKAAUFPOS=:VKAAUFPOS:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM VKADR   "
                                     + "WHERE  VKAMANDANT=:VKAMANDANT: AND VKASA=:VKASA: AND VKAAUFKRS=:VKAAUFKRS: AND VKAAUFLFD=:VKAAUFLFD:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 99:
                    or1.CommandText = "SELECT * FROM VKADR  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            Result.Tables[0].TableName = "VKADR";
            return Result;
        }
        public void DeleteVKADR(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "DELETE FROM VKADR   "
                        + "WHERE  VKAMANDANT=:VKAMANDANT:   AND VKASA=:VKASA:   AND VKAAUFKRS=:VKAAUFKRS:  ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 1:
                    or1.CommandText = "DELETE FROM VKADR   "
                                   + "WHERE  VKAMANDANT=:VKAMANDANT: AND VKASA=:VKASA: AND VKAAUFKRS=:VKAAUFKRS: AND VKAAUFLFD=:VKAAUFLFD: AND VKAAUFPOS=:VKAAUFPOS:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 20:
                    or1.CommandText = "DELETE FROM VKADR   "
                                   + "WHERE  VKAMANDANT=:VKAMANDANT: AND VKASA=:VKASA: AND VKAAUFKRS=:VKAAUFKRS: AND VKAAUFLFD=:VKAAUFLFD:  " + dwData["VKAAUFPOS"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateVKADR(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            if (option == 0)
            {
                switch (app.company)
                {
                    default:
                    case "YGR":
                    case "TST":
                        option = 1;
                        break;
                }
            }
            if (dwData != null)
            {
                dwData["VKAAENB"] = app.User; ;
                dwData["VKAAEND"] = date;
            }
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE VKADR SET VKAMANDANT=:VKAMANDANT:,VKASA=:VKASA:,VKAAUFKRS=:VKAAUFKRS:,VKAAUFLFD=:VKAAUFLFD:,VKAAUFPOS=:VKAAUFPOS:,VKAAENDST=:VKAAENDST:,VKALNAME1=:VKALNAME1:,VKALNAME2=:VKALNAME2:,VKALSTRASSE1=:VKALSTRASSE1:,VKALSTRASSE2=:VKALSTRASSE2:,VKALLKZ=:VKALLKZ:,VKALPLZ=:VKALPLZ:,VKALORT=:VKALORT:,VKALBZ=:VKALBZ:,VKALBZBEZ=:VKALBZBEZ:,VKALCOUNTY=:VKALCOUNTY:,VKALCITY=:VKALCITY:,VKABNAME1=:VKABNAME1:,VKABNAME2=:VKABNAME2:,VKABSTRASSE1=:VKABSTRASSE1:,VKABSTRASSE2=:VKABSTRASSE2:,VKABLKZ=:VKABLKZ:,VKABPLZPF=:VKABPLZPF:,VKABPOSTF=:VKABPOSTF:,VKABPLZ=:VKABPLZ:,VKABORT=:VKABORT:,VKABBZ=:VKABBZ:,VKABBZBEZ=:VKABBZBEZ:,VKABCOUNTY=:VKABCOUNTY:,VKABCITY=:VKABCITY:,VKABANSPNA=:VKABANSPNA:,VKAADRSL1=:VKAADRSL1:,VKAKUNDNR1=:VKAKUNDNR1:,VKAANZ1=:VKAANZ1:,VKAADRSLK11=:VKAADRSLK11:,VKAKUNDNRK11=:VKAKUNDNRK11:,VKAANZK11=:VKAANZK11:,VKAADRSLK21=:VKAADRSLK21:,VKAKUNDNRK21=:VKAKUNDNRK21:,VKAANZK21=:VKAANZK21:,VKAADRSL2=:VKAADRSL2:,VKAKUNDNR2=:VKAKUNDNR2:,VKAANZ2=:VKAANZ2:,VKAADRSLK12=:VKAADRSLK12:,VKAKUNDNRK12=:VKAKUNDNRK12:,VKAANZK12=:VKAANZK12:,VKAADRSLK22=:VKAADRSLK22:,VKAKUNDNRK22=:VKAKUNDNRK22:,VKAANZK22=:VKAANZK22:,VKAADRSL3=:VKAADRSL3:,VKAKUNDNR3=:VKAKUNDNR3:,VKAANZ3=:VKAANZ3:,VKAADRSLK13=:VKAADRSLK13:,VKAKUNDNRK13=:VKAKUNDNRK13:,VKAANZK13=:VKAANZK13:,VKAADRSLK23=:VKAADRSLK23:,VKAKUNDNRK23=:VKAKUNDNRK23:,VKAANZK23=:VKAANZK23:,VKAFREITXT=:VKAFREITXT:,VKAAESTAT=:VKAAESTAT:,VKABESTTXT=:VKABESTTXT:,VKAFILLER4=:VKAFILLER4:,VKAAENZL=:VKAAENZL:,VKAAENB=:VKAAENB:,VKAAEND=:VKAAEND:,VKANEUB=:VKANEUB:,VKANEUD=:VKANEUD:"
                        + "WHERE  VKAMANDANT=:VKAMANDANT: AND VKASA=:VKASA: AND VKAAUFKRS=:VKAAUFKRS: AND VKAAUFLFD=:VKAAUFLFD: AND VKAAUFPOS=:VKAAUFPOS:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
